package com.lsq.baseadmin.modules.maintenance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lsq.baseadmin.modules.maintenance.entity.ScheduleJob;
import com.lsq.baseadmin.modules.maintenance.mapper.ScheduleJobMapper;
import com.lsq.baseadmin.modules.maintenance.service.ScheduleJobService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 计划任务 服务实现类
 * </p>
 *
 * @author lsq
 * @since 2020-11-09
 */
@Service
public class ScheduleJobServiceImpl extends ServiceImpl<ScheduleJobMapper, ScheduleJob> implements ScheduleJobService {

    @Override
    public List<ScheduleJob> list(ScheduleJob scheduleJob) {
        QueryWrapper<ScheduleJob> wrapper = createWrapper(scheduleJob);
        return baseMapper.selectList(wrapper);
    }

    @Override
    public PageInfo pg(ScheduleJob scheduleJob, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ScheduleJob> list = list(scheduleJob);
        return new PageInfo<>(list);
    }


    private QueryWrapper<ScheduleJob> createWrapper(ScheduleJob scheduleJob) {
        QueryWrapper<ScheduleJob> wrapper = new QueryWrapper<>();
        if(null == scheduleJob) {
            return wrapper;
        }

        if(StringUtils.hasText(scheduleJob.getName())) {
            wrapper.like("name", scheduleJob.getName());
        }

        return wrapper;
    }
}
